import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SpuOrderVo, SpuOrderForm, SpuOrderQuery, SpuOrderAssignVo, SpuOrderAssignForm, SpuOrderAssignQuery } from '@/api/trade/order/types';

/**
 * 查询订单信息列表
 * @param query
 * @returns {*}
 */

export const listSpuOrder = (query?: SpuOrderQuery): AxiosPromise<SpuOrderVo[]> => {
  return request({
    url: '/lawyer/spuOrder/list',
    method: 'get',
    params: query
  });
};

export const listAssignOrder = (query?: SpuOrderAssignQuery): AxiosPromise<SpuOrderAssignVo[]> => {
  return request({
    url: '/lawyer/spuOrder/listAssignOrder',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单信息详细
 * @param orderId
 */
export const getSpuOrder = (orderId: string | number): AxiosPromise<SpuOrderAssignVo> => {
  return request({
    url: '/lawyer/spuOrder/' + orderId,
    method: 'get'
  });
};

/**
 * 新增订单信息
 * @param data
 */
export const addSpuOrder = (data: SpuOrderForm) => {
  return request({
    url: '/lawyer/spuOrder/saveSpuOrder',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单信息
 * @param data
 */
export const updateSpuOrder = (data: SpuOrderForm) => {
  return request({
    url: '/lawyer/spuOrder/updateSpuOrder',
    method: 'post',
    data: data
  });
};

/**
 * 删除订单信息
 * @param orderId
 */
export const delSpuOrder = (orderId: string | number | Array<string | number>) => {
  return request({
    url: '/lawyer/spuOrder/removeSpuOrder/' + orderId,
    method: 'delete'
  });
};

export const createOrder = (spuId: string | number) => {
  const data = {
    spuId
  };
  return request({
    url: '/lawyer/spuOrder/createOrder',
    method: 'post',
    data: data
  });
};

export const assignOrder = (orderId: string, lawFirmId: string | number) => {
  const data = {
    orderId,
    lawFirmId
  };
  return request({
    url: '/lawyer/spuOrder/assignOrder',
    method: 'post',
    data: data
  });
};

export const revokeOrder = (trackingNumber: string) => {
  const data = {
    trackingNumber
  };
  return request({
    url: '/lawyer/spuOrder/revokeOrder',
    method: 'post',
    data: data
  });
};
